package com.example.demo.ProxyMode;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * 场景类(动态代理)
 */
public class Client3 {

    public static void main(String[] args) {
        // 定义一个玩家
        IGamePlayer3 gamePlayer3 = new GamePlayer3("张三");
        // 定义一个handler
        InvocationHandler handler = new GamePlayIH(gamePlayer3);
        // 获取类的classLoder
        ClassLoader classLoader = handler.getClass().getClassLoader();
        // 动态生成一个代理者
        IGamePlayer3 proxy = (IGamePlayer3) Proxy.newProxyInstance(classLoader, new Class[]{IGamePlayer3.class}, handler);
        proxy.login("zhangSan", "password");
        proxy.killBoss();
        proxy.upgrade();
    }
}
